pub trait RequestValidator {
    fn validate(&self) -> anyhow::Result<()>;
}

pub trait RequestValidatorField {
    fn is_blank(&self) -> bool;
}

pub fn is_not_blank<T>(v: T) -> bool
where
    T: RequestValidatorField,
{
    !v.is_blank()
}

impl RequestValidatorField for String {
    fn is_blank(&self) -> bool {
        self.trim().is_empty()
    }
}

impl RequestValidatorField for &str {
    fn is_blank(&self) -> bool {
        self.trim().is_empty()
    }
}

impl<T> RequestValidatorField for Option<T>
where
    T: RequestValidatorField,
{
    fn is_blank(&self) -> bool {
        match self {
            Some(v) => v.is_blank(),
            None => true,
        }
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_is_not_blank_valitor() {
        let v = String::from("  ");
        println!("{}", v.is_blank());

        let v = Some("");
        println!("{}", v.is_blank());
    }
}
